package org.springblade.modules.notice.core.mq;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.aliyun.openservices.ons.api.PropertyValueConst;
import com.github.thierrysquirrel.annotation.MessageListener;
import com.github.thierrysquirrel.annotation.RocketListener;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.notice.core.DelayProcess;
import org.springblade.modules.notice.vo.NoticeTask;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;

/**
 * @Author ysq
 * @Date 2024/12/04
 * @Description 延时消息消费者
 */
@Slf4j
//@RocketListener(groupID = "GID_DELAY_MSG",messageModel = PropertyValueConst.BROADCASTING)
public class DelayNoticeConsumer {

	@Resource
	private DelayProcess delayProcess;
	@Resource
	private Environment environment;

	@MessageListener(topic = "delay_msg")
	public void receive(String message) {
		NoticeTask task = JSONUtil.toBean(message, NoticeTask.class);
		//当前环境
		String curEnvironment = environment.getActiveProfiles()[0];
		if (Func.equalsSafe(curEnvironment, task.getEnv())) {
			log.info("延迟消息通知,发送时间:[{}], 接收内容:[{}]", DateUtil.now(), message);
			delayProcess.noticeBusinessProcess(task);
		}
	}
}
